package com.itheima.doudizhu2;

import java.util.*;
//斗地主综合案例
public class PokerGame {

    static HashMap<Integer, String> hm = new HashMap<>();//记录序号和牌的对应关系
    static ArrayList<Integer> list = new ArrayList<>();//记录序号

    static {
        String [] colors = {"♥","♠","♣","♦"};
        String [] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        int serialNumber = 1;
        for (String number : numbers){
            for (String color : colors){
                hm.put(serialNumber,color+number);
                list.add(serialNumber);
                serialNumber++;
            }
        }
        hm.put(serialNumber,"大王");
        list.add(serialNumber);
        serialNumber++;
        hm.put(serialNumber,"小王");
        list.add(serialNumber);

    }


    public PokerGame(){
        //洗牌
        Collections.shuffle(list);

        //发牌(treeset可以自动排序)
        TreeSet<Integer> lord = new TreeSet<>();
        TreeSet<Integer> player1 = new TreeSet<>();
        TreeSet<Integer> player2 = new TreeSet<>();
        TreeSet<Integer> player3 = new TreeSet<>();

        for (int i = 0; i < list.size(); i++) {
            int serialNumber = list.get(i);

            if(i<=2){
                lord.add(serialNumber);
                continue;
            }

            if (i % 3 == 0) {
                player1.add(serialNumber);
            } else if (i % 3 == 1) {
                player2.add(serialNumber);
            }else{
                player3.add(serialNumber);
            }
        }//for的
        lookPoker("底牌",lord);
        lookPoker("钢脑壳",player1);
        lookPoker("大帅比",player2);
        lookPoker("蛋筒",player3);

    }


    public void lookPoker(String name,TreeSet<Integer> ts){
        System.out.print(name+"：");
        for (int serialNumber : ts) {
            String poker = hm.get(serialNumber);
            System.out.print(poker+" ");
        }
        System.out.println();
    }

}
